using System;
using System.Globalization;
using System.IO;

namespace Atomic.Vasp.Options
{
	/// <summary>
	/// Tetrahedron smearing (ISMEAR=-5,-4).
	/// http://cms.mpi.univie.ac.at/vasp/guide/node124.html
	/// </summary>
	[Serializable]
	public class TetrahedronSmearing : VaspOption
	{
		public TetrahedronSmearing()
			: this(true)
		{
		}

		public TetrahedronSmearing(bool blochlCorrections)
			: this(blochlCorrections, null)
		{
		}

		public TetrahedronSmearing(bool blochlCorrections, double? sigma)
		{
			if (sigma.HasValue && sigma.Value <= 0.0)
			{
				throw new ArgumentException();
			}

			BlochlCorrections = blochlCorrections;
			Sigma = sigma;
		}

		public override void Write(VaspIncar incar, DirectoryInfo directory)
		{
			if (BlochlCorrections)
			{
				incar.Add("ISMEAR", "-5", "Tetrahedron method smearing with Blöchl corrections");
			}
			else
			{	
				incar.Add("ISMEAR", "-4", "Tetrahedron method smearing without Blöchl corrections");
			}

			if (Sigma.HasValue)
			{
				incar.Add("SIGMA", Sigma.Value.ToString(CultureInfo.InvariantCulture));
			}
		}

		public bool BlochlCorrections
		{
			get;
			private set;
		}

		public double? Sigma
		{
			get;
			private set;
		}
	}
}
